<template>
  <div class="layout-container" :class="{ old: elder }">
    <div class="layout-section">
      <top-header :show-elder="false" :auth-check="true" @setElder="setElderByChild"></top-header>

      <div class="home-que-tit">历史查询</div>

      <div class="item_box">
        <div class="item_seach" v-if="false">
          <input type="text" placeholder="请输入查询关键字"/>
          <img class="seach_icon" src="@/assets/jzy/seach.png" alt="" />
        </div>
        <div class="item_list" v-for="data in list"
             @click="showDetail(data.unid,data.usertype,data.infotype,data.handlestate);">
          <img v-if="data.infotype === 0" class="imgtit" src="@/assets/jzy/icons_0.png" alt=""/>
          <img v-if="data.infotype === 1" class="imgtit" src="@/assets/jzy/icons_1.png" alt=""/>
          <img v-if="data.infotype === 2" class="imgtit" src="@/assets/jzy/icons_2.png" alt=""/>
          <div class="item_center">
            <div class="item_name">{{ data.unitName }}</div>
            <div class="item_time">{{ data.createTime }}</div>
          </div>
          <img v-if="data.handlestate === '办结'" class="imgtit" src="@/assets/jzy/type_0.png" alt=""/>
          <img v-if="data.handlestate === '退回' || data.handlestate === '不予受理' || data.handlestate === '已补齐补正'"
               class="imgtit" src="@/assets/jzy/type_6.png" alt=""/>
          <img v-if="data.handlestate === '补齐补正'" class="imgtit" src="@/assets/jzy/type_2.png" alt=""/>
          <img v-if="data.handlestate === '待办'" class="imgtit" src="@/assets/jzy/type_4.png" alt=""/>
          <img v-if="data.handlestate === '在办'" class="imgtit" src="@/assets/jzy/type_1.png" alt=""/>
          <img v-if="data.handlestate === '过期'" class="imgtit" src="@/assets/jzy/type_5.png" alt=""/>
          <img v-if="data.handlestate === '草稿'" class="imgtit" src="@/assets/jzy/type_3.png" alt=""/>
        </div>
      </div>

      <div class="item_box" v-if="list.length===0" style="text-align: center; color: #ff0000;">
        无相关查询记录
      </div>

      <footer-right></footer-right>
    </div>

    <footer-nav :active-index="3"></footer-nav>
  </div>
</template>

<script>
import FooterNav from "@/components/footerNav";
import FooterRight from "@/components/footerRight";
import TopHeader from "@/components/topHeader";
import {apiGetList} from "@/api/apply";
import {ajaxUtils} from "@/utils/lwUtils";

export default {
  components: {TopHeader, FooterRight, FooterNav},
  data() {
    return {
      activeNames: ['1'],
      homeTab: 0,
      elder: false,
      list: [],
    }
  },
  created() {
    this.loadList(1);
  },
  methods: {
    //子组件调用方法，设置老年模式
    setElderByChild: function (elder) {
      this.elder = elder;
    },
    loadList: function (page) {
      apiGetList(page).then(res => {
        if (ajaxUtils.checkFail(res.code,res.msg)) {
          return;
        }
        this.list = res.data;
      }).catch(() => {
      });
    },
    showDetail: function (unid, usertype, infoType, handlestate) {
      if (handlestate === "过期") {
        this.$eraqDlg.alert("已过档案查看期限，请重新申请查询。");
        return;
      }
      //查询基本信息、变更信息时，状态为办结，则直接打开查看页
      if (infoType !== 2) {
        this.showDetailBase(unid, usertype, infoType, handlestate);
        return;
      }
      this.showDetailInner(unid, usertype, infoType, handlestate);
    },
    showDetailBase: function (unid, usertype, infoType, handlestate) {
      if (handlestate !== "办结") {
        this.$router.push({path: "/edit", query: {unid, usertype}});
        return;
      }
      this.$router.push({path: "/showBase", query: {unid, usertype, type: infoType}});
    },
    showDetailInner: function (unid, usertype, infoType, handlestate) {
      if (handlestate === "待办") {
        if (usertype === 0 && infoType === 2) {
          this.$router.push({path: "/realAuth", query: {unid, usertype}});
        } else {
          this.$eraqDlg.alert("申请审批将在3个工作日之内办结。");
        }
        return;
      }
      if (handlestate === "在办" || handlestate === "已补齐补正") {
        this.$eraqDlg.alert("申请审批将在3个工作日之内办结。");
        return;
      }
      if (handlestate === "草稿" || handlestate === "补齐补正") {
        this.$router.push({path: "/patch", query: {unid, usertype}});
        return;
      }
      if (handlestate === "退回" || handlestate === "不予受理") {
        this.$eraqDlg.alert("您的查询申请未通过审批。");
        return;
      }
      this.$router.push({path: "/showInner", query: {unid, usertype}});
    },
  },
}
</script>

<style lang='scss' scoped>
@import "src/css/home";
@import "src/css/jzy";
</style>
